import request from '@/utils/axios'
import { QueryParams, UserCounselorData, UserCounselorResponse } from './types'
import type { AxiosResponse } from "axios";

/**
 * 用于调用 API 接口的函数
 * @method CounselorApi 获取咨询师相关
 */

export default {
    // 获取咨询师列表
    getUserCounselors(params?: QueryParams): Promise<AxiosResponse<UserCounselorResponse>> {
      return request({
        url: '/api/userCounselor',
        method: 'get',
        params
      })
    },
  
    // 获取单个咨询师信息
    getUserCounselor(userId: string | number): Promise<AxiosResponse<UserCounselorData>> {
      return request({
        url: `/api/userCounselor/${userId}`,
        method: 'get'
      })
    },
  
    // 创建咨询师
    createUserCounselor(data: UserCounselorData): Promise<AxiosResponse<UserCounselorData>> {
      return request({
        url: '/api/userCounselor',
        method: 'post',
        headers: {
          'Content-Type': 'application/json'
        },
        data
      })
    },
  
    // 批量创建咨询师
    createUserCounselors(counselorList: UserCounselorData[]): Promise<AxiosResponse<UserCounselorData>> {
      const formData = new FormData()
      formData.append('UserCounselorList', JSON.stringify(counselorList))
  
      return request({
        url: '/api/userCounselor',
        method: 'post',
        data: formData
      })
    },
  
   // 更新咨询师信息
  updateCounselor(userId: string, data: UserCounselorData) {
    return request({
      url: `/api/userCounselor/${userId}`,
      method: 'put',
      headers: {
        'Content-Type': 'application/json'  // 添加 Content-Type 头
      },
      data: JSON.stringify(data)  // 序列化数据
    })
  },
  
    // 删除咨询师
    deleteUserCounselor(userId: string | number): Promise<AxiosResponse<UserCounselorData>> {
      return request({
        url: `/api/userCounselor/${userId}`,
        method: 'delete'
      })
    }
  }